package com.sskj.xgja.verify;


import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.sskj.base.data.User;
import com.sskj.xgja.AppManager;
import com.sskj.xgja.LiveDataBus;
import com.sskj.xgja.MVPActivity;
import com.sskj.base.view.ToolBarLayout;
import com.sskj.xgja.R;

import butterknife.BindView;

/**
 * @author Hey
 * Create at  2019/03/20
 */
public class Verify4Activity extends MVPActivity<Verify4Presenter> {

    @BindView(R.id.toolbar)
    ToolBarLayout toolbar;
    @BindView(R.id.verify_status)
    ImageView verifyStatus;
    @BindView(R.id.verify_text)
    TextView verifyText;
    @BindView(R.id.submit)
    Button verifyButton;

    @Override
    public int getLayoutId() {
        return R.layout.activity_verify4;
    }

    @Override
    public Verify4Presenter getPresenter() {
        return new Verify4Presenter();
    }

    @Override
    public void initView() {
        toolbar.setLeftButtonOnClickListener(v -> {
            finish();
            AppManager.getInstance().finishVerify();
        });
        mPresenter.getAccountDetail("",true);
    }


    @Override
    public void initData() {

    }

    public void updateUi(String data) {
        verifyText.setText("审核失败,失败原因:" + data);
    }

    public static void start(Context context) {
        Intent intent = new Intent(context, Verify4Activity.class);
        context.startActivity(intent);
    }

    public void setAccountInfo(User data) {
//        userViewModel.setUser(this, data);
        LiveDataBus.get().with(1,User.class).postValue(data);

        switch (data.getAuthStatus()) {
            case "3":
                verifyStatus.setImageResource(R.mipmap.icon_audit_success);
                verifyText.setText("认证成功");
                break;
            case "2":
                verifyStatus.setImageResource(R.mipmap.icon_auditing);
                verifyText.setText("审核中,请耐心等待");
                break;
            case "4":
                mPresenter.getReason(true);
                verifyStatus.setImageResource(R.mipmap.icon_audit_fail);
                verifyButton.setVisibility(View.VISIBLE);
                verifyButton.setText("重新提交");
                verifyButton.setOnClickListener(v -> {
                    Verify1Activity.start(this);
                    finish();
                });
                break;
        }
    }

    public void onBackPressed() {
        finish();
        AppManager.getInstance().finishVerify();
        super.onBackPressed();
    }

}
